<!-- 修改 木遥（微信:  http://marsgis.cn/weixin.html ） -->
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="https://muyao1987.gitee.io/cdn/marsgis.cn/favicon/favicon.ico" />
    <title>CZML图层 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <script
      type="text/javascript"
      src="/lib/include-lib.js"
      libpath="/lib/"
      include="jquery,layer,toastr,font-awesome,bootstrap,layer,haoutil,ztree,mars3d"
    ></script>

    <!--支持agi_conicSensor，agi_customPatternSensor和agi_rectangularSensor展示的czml插件-->
    <script src="/lib/mars3d/thirdParty/sensorVolumes/cesium-sensor-volumes.js"></script>

    <link href="/css/style.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <div id="mars3dContainer" class="mars3d-container"></div>

    <div id="viewSL" class="infoview">
      示例：
      <input type="button" class="btn btn-primary" value="飞机" onclick="showAircraft()" />
      <input type="button" class="btn btn-primary" value="船舶" onclick="showShip()" />
      <input type="button" class="btn btn-primary" value="汽车" onclick="showCar()" />
      <input type="button" class="btn btn-primary" value="卫星" onclick="showSatellite()" />
      <input type="button" class="btn btn-primary" value="北斗卫星" onclick="showBDSatellite()" />
      <input type="button" class="btn btn-primary" value="火箭发射" onclick="showRocket()" />
      <input type="button" class="btn btn-primary" value="消防演练" onclick="showFireDrill()" />
    </div>

    <div class="infoview" style="overflow: auto; right: 5px; left: auto; top: 80px; max-height: 88%">
      <button id="btnNoCheck" class="btn btn-primary" style="margin: 5px 20px; display: none">取消锁定</button>
      <ul id="treeOverlays" class="ztree"></ul>
    </div>

    <script src="/js/common.js"></script>
    <script src="./map.js"></script>
    <script type="text/javascript">
      "use script" //开发环境建议开启严格模式

      function initUI(options) {
        eventTarget.on("loadGraphicLayer", (e) => {
          initTree(e.data.list)
        })
      }

      //===========================树控件处理============================
      let layersObj = {}

      function initTree(arr, nameColum = "name") {
        //初始化树
        let setting = {
          check: {
            enable: true
          },
          data: {
            simpleData: {
              enable: true
            }
          },
          callback: {
            onCheck: treeOverlays_onCheck,
            onClick: treeOverlays_onClick
          }
        }

        let zNodes = []
        let pnode = {
          id: -1,
          name: "全部",
          type: "group",
          open: false,
          checked: true,
          icon: "/lib/jquery/ztree/css/mars/images/folder.png"
        }
        zNodes.push(pnode)

        for (let i = 0, len = arr.length; i < len; i++) {
          let item = arr[i]
          let name = item[nameColum] || "未命名"

          let node = {
            id: i,
            pId: pnode.id,
            name: name,
            checked: true,
            icon: "/lib/jquery/ztree/css/mars/images/layer.png"
          }

          node.open = true
          zNodes.push(node)

          layersObj[i] = item._entity
        }

        $.fn.zTree.destroy()
        $.fn.zTree.init($("#treeOverlays"), setting, zNodes)
      }

      function treeOverlays_onCheck(e, treeId) {
        let zTree = $.fn.zTree.getZTreeObj(treeId)

        //获得所有改变check状态的节点
        let changedNodes = zTree.getChangeCheckedNodes()
        for (let i = 0; i < changedNodes.length; i++) {
          let treeNode = changedNodes[i]
          treeNode.checkedOld = treeNode.checked
          let entity = layersObj[treeNode.id]
          if (entity == null) {
            continue
          }
          let show = treeNode.checked
          //处理图层显示隐藏
          entity.show = show
          if (entity._labelEx) {
            entity._labelEx.show = show
          }
        }
      }

      function treeOverlays_onClick(event, treeId, treeNode) {
        let entity = layersObj[treeNode.id]
        if (entity == null) {
          return
        }
        map.flyTo(entity)
      }
    </script>
  </body>
</html>
